//
//  MHOpenRedPacketView.m
//  MiaoCircle
//
//  Created by 许正荣 on 2018/11/9.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHOpenRedPacketView.h"

@interface  MHOpenRedPacketView()


@end

@implementation MHOpenRedPacketView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self _setupSubViews];
    }
    return self;
}

-(void) _setupSubViews
{
    
    UIImageView *animatedImage = [[UIImageView alloc] init];
    animatedImage.contentMode = UIViewContentModeScaleAspectFill;
    animatedImage.clipsToBounds = YES;
    animatedImage.image = [UIImage imageNamed:@"bg_video_package_light"];
    [self addSubview:animatedImage];
    self.lightImage = animatedImage;
    [self addRedPacket];
    
    self.redPacketBtn = [[UIButton alloc] init];
    [self.redPacketBtn setBackgroundImage:[UIImage imageNamed:@"bg_video_package"] forState:0];
    [self addSubview:self.redPacketBtn];
    
    self.amountLabel = [UILabel new];
    self.amountLabel.textColor = MHColorFromHexString(@"#DD2B2C");
    self.amountLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.amountLabel];
    
    self.remakLabel = [UILabel new];
    self.remakLabel.textColor = MHColorFromHexString(@"#DD2B2C");
    self.remakLabel.font = MHRegularFont_10;
    self.remakLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.remakLabel];

    
  
    
    
    
}


-(void) addRedPacket
{
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    animation.fromValue = [NSNumber numberWithFloat:0.f];
    animation.toValue = [NSNumber numberWithFloat: M_PI *2];
    animation.duration = 3;
    animation.autoreverses = NO;
    animation.fillMode = kCAFillModeForwards;
    animation.repeatCount = MAXFLOAT;
    [self.lightImage.layer addAnimation:animation forKey:nil];
}

-(void)dealloc
{
    [self.lightImage.layer removeAllAnimations];
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    [self.redPacketBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self).with.inset(20);
    }];
    
    [self.remakLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.redPacketBtn);
        make.top.equalTo(self.redPacketBtn).offset(3);
    }];
    
    [self.amountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.redPacketBtn);
        make.top.equalTo(self.remakLabel).offset(15);
    }];
    
    [self.lightImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    
}


@end
